<?php

/**
 * 根据注册参数获取注册方式
 * @param  string  &$username [用户名]
 * @param  string  &$email    [email]
 * @param  string  &$mobile   [mobile]
 * @param  integer &$type     [注册方式]
 * @return [type]             [description]
 */
function get_reg_username($username , &$email , &$mobile ,&$type = 0) {
	
	if($type) {

	}else{
		$check_email  = preg_match("/[a-z0-9_\-\.]+@[a-z0-9]+[_\-]?\.+[a-z]{2,3}/i", $username, $match_email);
		$check_mobile = preg_match("/^(1[3|4|5|8])[0-9]{9}$/", $username, $match_mobile);
        //判断username是否是邮箱
        if($match_email) {
			$email    = $username;
			$type     = C('USER_REG_TYPE.EMAIL');
			$username = '';
			$mobile   = '';
        }elseif($match_mobile) {
			$mobile   = $username;
			$type     = C('USER_REG_TYPE.MOBILE');
			$username = '';
			$email    = '';
        }else{
			$type     = C('USER_REG_TYPE.USERNAME');
			$mobile   = '';
			$email    = '';
        }
	}

	return true;
}

/**
 * 检查注册方式
 * @param  int $regType [页面传过来的注册方式]
 * @param  int $type    [根据用户名获取的注册方式]
 * @return bool/string          
 */
function get_reg_type($regType , $type) {

	if($regType == 'email' && $type != C('USER_REG_TYPE.EMAIL')) {
		return '邮箱格式不正确';
	}
	if($regType == 'mobile' && $type != C('USER_REG_TYPE.MOBILE')) {
		return '手机格式不正确';
	}
	if($regType == 'username' && $type != C('USER_REG_TYPE.USERNAME')) {
		return '用户名格式不正确';
	}
	//检查当前的注册方式是否开启
	if(!check_regType_open($type)) {
		return '该类型未开放注册';
	}
	return true;
}

function check_regType_open($type) {
	return true;
}

/**
 * [safe_html_fiter description]
 * @param  [type] $var [description]
 * @return [type]      [description]
 */
function safe_html_fiter($var) {
 return $var;
}